/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tkgarment.system.dao;

import com.tkgarment.system.domain.Religion;
import com.tkgarment.system.factory.DAOFactory;
import com.tkgarment.system.inf.IDAO;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zraj
 */
public class ReligionDAO extends AbstractDAO implements IDAO<Religion, Integer> {

    @Override
    public List<Religion> getAll() throws Exception {
       String sql = "select * from religion order by "+ Religion.field_religion_name +" ASC";
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        List<Map<String,Object>> result = this.getCon().queryList(sql);
        List<Religion> rs = new ArrayList<>();
         for (Map<String, Object> map : result) {
            Religion r = new Religion();
            r.setReligionID(Integer.parseInt(map.get(Religion.field_religion_id).toString()));
            r.setReligionName(map.get(Religion.field_religion_name).toString());
            rs.add(r);
        }
         return rs;
    }

    public Religion getById(Integer id) throws Exception {
         
        String sql = "select * from religion where "+ Religion.field_religion_id +" = ? ";
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        Map<String,Object> map = this.getCon().querySingle(sql,id);
      
       
            Religion r = new Religion();
            r.setReligionID(Integer.parseInt(map.get(Religion.field_religion_id).toString()));
            r.setReligionName(map.get(Religion.field_religion_name).toString());
           
      
        
        
        return r;
    }
    
    
    @Override
    public int updateSingle(Religion t, Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int deleteSingle(Religion t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int insertSingle(Religion t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
